import { getProductList,getProductArea } from '../../../../common/api/index'
Page({
	onShareAppMessage() {
	  return {
		  
	  }
	},
	data: {
		areaData:[],
		dataList:[],
		keyword: '',
		pageNo: 1,
		bgImg:'http://8.149.131.154/bg.png',
		background: ['https://www.liyacq.cn/banner3.jpg','https://www.liyacq.cn/banner2.jpg','https://www.liyacq.cn/banner1.jpg'],
		headList:[
			{ name: '公司简介', img: '/static/image/gongsijianjie.png', path:"/pages/component/mine/company/intro/index" },
			{ name: '素材中心', img: '/static/image/sucaizhongxin.png' },
			{ name: '加入我们', img: '/static/image/hezuo.png',path:'/pages/component/vip/poster/index' },
		],
		indicatorDots: false,
		vertical: false,
		autoplay: true,
		interval: 4000,
		duration: 1000,
		Height: '360rpx',
	},
	onShow() {
		this.getAreaData()
		this.getGoodsList()
	},
	// search中input改变
	onChangeSearch(e){
		this.setData({
			keyword: e.detail
		})
	},
	// 商品专区
	getAreaData(){
		getProductArea().then(res => {
			if(res.code == 200){
				this.setData({
					areaData: res.data
				})
			}
		})
	},
	// 获取首页商品列表
	getGoodsList(){
		let data = {
			pageNo: this.data.pageNo,
			pageSize: 10,
			showIndexFlag: true,
			keyword:this.data.keyword
		}
		getProductList(data).then(res => {
			if(res.code == 200){
				this.setData({
					dataList: res.data,
					total: res.extend.total
				})
			}
		})
	},
	// 提交搜索
	onSearchSubmit(){
		this.setData({
			pageNo: 1,
			dataList:[],
		})
		this.getGoodsList()
	},
	// 跳转分类
	toArea(e){
		let areaId = e.currentTarget.dataset.id
		let areaName = e.currentTarget.dataset.name
		let login = wx.getStorageSync('isLogin') || false;
		if(login){
			wx.navigateTo({
				url: '/pages/component/classify/area/index?id=' + areaId + '&areaName=' + areaName
			})
		}else{
			wx.showToast({
				title: '请先登录',
				icon: 'none',
				duration: 2000
			})
			setTimeout(() => {
				let page = getCurrentPages()[0].route;
				wx.setStorageSync('currentPath', page)
				wx.reLaunch({
				  url: '/pages/component/mine/account/login/index',
				})
			},2000)
		}
	},
	// 跳转设置
	clickToPath(e){
		let path = e.currentTarget.dataset.path
		wx.$goTo(path,true)
	},



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})